import { Fixed } from 'gantd/lib/grid';
import { getUserField } from '@/utils/user';
import { UserSelector } from '@/components/selectors';

// 表格列设置
const TableFieldsSchemaWithStyle = [
  {
    fieldName: 'bomRoom',
    title: 'EBOM房间编号',
    width: 90,
    fixed: Fixed.left,
  },
  {
    fieldName: 'xbomNo',
    title: 'XBom编号',
    width: 90,
    fixed: Fixed.left,
  },
  {
    fieldName: 'orderNo',
    title: '订单号',
    width: 150,
    fixed: Fixed.left,
  },
  {
    fieldName: 'basicPno18',
    title: '基础PNO18',
    width: 140,
  },
  {
    fieldName: 'specialPno18',
    title: '特改PNO18',
    width: 140,
  },
  {
    fieldName: 'requirementDesc',
    title: '需求描述',
    width: 200,
  },
  {
    fieldName: 'state',
    title: '状态',
    width: 80,
    valueFormatter: (params: any) => params.value,
    editConfig: {
      editable: false,
    },
  },
  {
    fieldName: 'authPersonsStr',
    title: 'MBOM工程师',
    width: 100,
    valueFormatter: (params: any) => {
      const { value } = params;
      if (!value) return;
      const userIdList = value.split(',');
      return userIdList.map((i) => getUserField({ id: i })).join(',');
    },
    editConfig: {
      component: UserSelector,
      editable: false,
      props: {
        useStorage: false,
        allowClear: true,
      },
      rules: {
        required: false,
      },
    },
  },
  {
    fieldName: 'owner',
    title: '责任人',
    width: 55,
    valueFormatter: (params: any) => {
      const { value } = params;
      if (!value) return;
      return getUserField({ id: value });
    },
    editConfig: {
      component: UserSelector,
      editable: true,
      props: {
        useStorage: false,
        allowClear: true,
      },
      rules: {
        required: true,
        message: tr('负责人必填'),
      },
    },
  },
  {
    fieldName: 'interfacePerson',
    title: '接口人',
    width: 55,
    // valueFormatter: (params: any) => {
    //   const { value } = params;
    //   if (!value) return;
    //   return getUserField({ id: value });
    // },
    // editConfig: {
    //   component: UserSelector,
    //   editable: true,
    //   props: {
    //     useStorage: false,
    //     allowClear: true,
    //   },
    //   rules: {
    //     required: true,
    //     message: tr('负责人必填'),
    //   },
    // },
  },
  {
    fieldName: 'helpPersonsStr',
    title: '协助人',
    width: 100,
    // valueFormatter: (params: any) => {
    //   const { value } = params;
    //   if (!value) return;
    //   const userIdList = value.split(',');
    //   return userIdList.map((i) => getUserField({ id: i })).join(',');
    // },
    // editConfig: {
    //   component: UserSelector,
    //   editable: false,
    //   props: {
    //     useStorage: false,
    //     allowClear: true,
    //   },
    //   rules: {
    //     required: false,
    //   },
    // },
  },
  {
    fieldName: 'dmsTime',
    title: 'DMS下发时间',
    width: 135,
  },
  {
    fieldName: 'orderQty',
    title: '订单数量',
    width: 60,
  },
  {
    fieldName: 'sapInnerOrderNo',
    title: 'SAP内部订单号',
    width: 135,
  },
];

const XBomGridSchema = {
  TableFieldsSchemaWithStyle,
  USAGE_VALUE_FIELD_NAME: 'USAGE_VALUE_FIELD_NAME', // 使用规则字段名，编辑的时候需要
};

export default XBomGridSchema;
